package com.lin.subject.infra.basic.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lin.subject.commom.enums.IsDeletedFlagEnum;
import com.lin.subject.infra.basic.entity.SubjectBrief;
import com.lin.subject.infra.basic.entity.SubjectRadio;
import com.lin.subject.infra.basic.mapper.SubjectRadioDao;
import com.lin.subject.infra.basic.service.SubjectRadioService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * @author jeremylin
 * @description 针对表【subject_radio(单选题信息表)】的数据库操作Service实现
 * @createDate 2024-10-21 11:11:10
 */
@Service
public class SubjectRadioServiceImpl extends ServiceImpl<SubjectRadioDao, SubjectRadio>
        implements SubjectRadioService {

    @Resource
    private SubjectRadioDao subjectRadioDao;

    /**
     * 批量插入
     *
     * @param radioList
     */
    @Override
    public void insertList(List<SubjectRadio> radioList) {
        this.saveBatch(radioList);
    }

    /**
     * 根据条件查询列表
     *
     * @param subjectRadio
     * @return
     */
    @Override
    public List<SubjectRadio> queryListByCondition(SubjectRadio subjectRadio) {
        LambdaQueryWrapper<SubjectRadio> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Objects.nonNull(subjectRadio.getSubjectId()),
                SubjectRadio::getSubjectId,subjectRadio.getSubjectId());
        return this.subjectRadioDao.selectList(queryWrapper);
    }

    @Override
    public void deleteSubject(Long id) {
        UpdateWrapper<SubjectRadio> updateWrapper = new UpdateWrapper<>();
        updateWrapper.lambda().set(SubjectRadio::getIsDeleted, IsDeletedFlagEnum.DELETED.getCode())
                .eq(SubjectRadio::getSubjectId, id);

        this.update(updateWrapper);
    }
}




